
import org.junit.Test;

import java.util.List;

import static org.mockito.Mockito.*;

public class SimpleTest {

    @Test
    public void simpleTest() {

        // 模拟获取第一个元素时，返回字符串first
        List<String> mockedList = mock(List.class);
        when(mockedList.get(0)).thenReturn("first");
        //此时打印first
        System.out.println(mockedList.get(0));


        // 模拟获取第二个元素时，抛出RuntimeException
        when(mockedList.get(1)).thenThrow(new RuntimeException());
        // 此时将会抛出RuntimeException
        System.out.println(mockedList.get(1));

//        list.clear();

//        verify(list).add("one");

        //设置方法的预期返回值  
//        when(list.get(0)).thenReturn("helloworld");
//        when(list.isEmpty());
//        String result = list.get(0);

        //验证方法调用(是否调用了get(0))  
//        verify(list).get(0);

        //junit测试  
//        Assert.assertEquals("helloworld", result);
    }
}  
